package Main;
// TODO can be delete
import java.io.*;

public class CmdMallet {

	String pathOut="c:\\a\\";
	String pathIn="c:\\a\\web\\";
	String pathMallet="C:\\Users\\admin\\Downloads\\mallet-2.0.6\\";
	String topicsFile="keys.txt";
	String articleTopicFile="topics.txt";
	String ldaFile="data.mallet";
	
	
	public CmdMallet(String pathOut, String pathIn,String topicsFile,String articleTopicFile,String ldaFile){
		this.pathOut = pathOut;
		this.pathIn = pathIn;
		this.topicsFile=topicsFile;
		this.articleTopicFile=articleTopicFile;
		this.ldaFile=ldaFile;
	}

	public CmdMallet(String pathOut, String pathIn,String topicsFile,String articleTopicFile,String ldaFile,String pathMallet){
		this.pathOut = pathOut;
		this.pathIn = pathIn;
		this.topicsFile=topicsFile;
		this.articleTopicFile=articleTopicFile;
		this.ldaFile=ldaFile;
		this.pathMallet=pathMallet;
	}
	
	public CmdMallet(){
		
	}
	
	public void buildLDA(int numOfTopics,int numOfIteration,int numWordsInTopic) {
		try {

			Runtime r = Runtime.getRuntime();	
			Process p = r.exec("cmd /c "+pathMallet+"bin\\mallet import-dir --input "+pathIn+" --output "+pathOut+ldaFile+" --keep-sequence --remove-stopwords");
			p.waitFor();
			System.out.println("CmdMallet done 1");//TODO done1 in CmdMallet
			p = r.exec("cmd /c "+pathMallet+"bin\\mallet train-topics --input "+pathOut+ldaFile+" --num-topics "+numOfTopics+" --num-iterations "+numOfIteration+" --output-doc-topics "+pathOut+articleTopicFile+" --num-top-words "+numWordsInTopic+" --output-topic-keys "+pathOut+topicsFile);
//			System.out.println("cmd /c "+pathMallet+"bin\\mallet train-topics --input "+pathOut+ldaFile+" --num-topics "+numOfTopics+" --num-iterations "+numOfIteration+" --output-doc-topics "+pathOut+articleTopicFile+" --num-top-words "+numWordsInTopic+" --output-topic-keys "+pathOut+topicsFile);//TODO
			p.waitFor();
			System.out.println("CmdMallet done 2");//TODO done2 in CmdMallet

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
